<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册页面</title>
    <script src="/res/jquery-3.6.0.min.js"></script>
</head>
<body>
***********注册************<br/>
    用户名：<input type="text" id="userName"><br/>
    密码：<input type="text" id="password"><br/>
    <button id="doRegister">注册</button>

</body>

<script>
    jQuery(function(){
        $("#doRegister").click(function(){
            var userName = $("#userName").val()
            var password = $("#password").val()

            var data = {}
            data['userName'] = userName
            data['password'] = password
            console.log('data-->'+data)

            $.ajax({
                type:'post',
                url:'/doRegister',
                data:JSON.stringify(data),//提交还是文本/字符串 data是json对象 转换成文本
                contentType:'application/json',//发送到服务器的类型
                success:function(ret){
                    if(ret){
                        window.location.href='/login'
                    }else{
                        alert('注册失败.')
                    }
                }
            })

        })
    })
</script>

</html>
